const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    trainId: null,
    memberAssessment: '',
    finishQuality: null,
    trainStrength: null,
    memberFeeling: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const trainId = wx.getStorageSync("trainId");
    const memberAssessment = wx.getStorageSync('memberAssessment');
    this.setData({
      trainId,
      memberAssessment
    });
  },
  bindTextArea: function(e) {
    this.setData({
      memberAssessment: e.detail.value
    });
  },
  changeQuality: function(e) {
    const value = e.currentTarget.dataset.value;
    this.setData({
      finishQuality: value
    });
  },
  changeStrength: function(e) {
    const value = e.currentTarget.dataset.value;
    this.setData({
      trainStrength: value
    });
  },
  changeFeeling: function(e) {
    const value = e.currentTarget.dataset.value;
    this.setData({
      memberFeeling: value
    });
  },
  save: function() {
    const memberAssessment = this.data.memberAssessment;
    const trainId = this.data.trainId;
    const url = app.globalData.url;
    wx.request({
      url: url + '/train/finishTrainByTrainee',
      data: {
        trainId,
        memberAssessment
      },
      method: 'POST',
      success: function(response) {
        if (response.data.success) {
          wx.navigateBack({
            delta: 2
          });
          wx.showToast({
            title: '保存成功',
            icon:'none'
          })
        } else {
          wx.showToast({
            title: '保存失败:' + response.data.message,
            icon: 'none'
          })
        }
      }
    })
  }
})